//加载页面数据
let goodsControllerApi = host+'/goods/findGoodsByBrandId.do'
let obj = parseQuery(location.search.slice(1))
let brandId = obj.brandId
$.get(goodsControllerApi,{brandId:brandId},(res)=>{
	console.log(res.info)
	let productsArr = res.info;
	let html = '';
	for(let i=0;i<productsArr.length;i++){
		html += `
			<dl>
				<dt data-id="${productsArr[0].goodsId}">
					<a href="cart-item.html?goodsId=${productsArr[0].goodsId}&brandId=${productsArr[0].brandId}">
						<img src="${productsArr[0].goodsImgUrl}" alt="">
					</a>
				</dt>
				<dd>${productsArr[0].goodsMsg}</dd>
				<dd>${productsArr[0].goodsName}</dd>
				<dd>¥${productsArr[0].minPrice} <span class="zan">&#xe6c8;</span></dd>
			</dl>
			<dl>
				<dt data-id="${productsArr[0].goodsId}">
					<a href="cart-item.html?goodsId=${productsArr[0].goodsId}&brandId=${productsArr[0].brandId}">
						<img src="${productsArr[0].goodsImgUrl}" alt="">
					</a>
				</dt>
				<dd>${productsArr[0].goodsMsg}</dd>
				<dd>${productsArr[0].goodsName}</dd>
				<dd>¥${productsArr[0].minPrice} <span class="zan">&#xe6c8;</span></dd>
			</dl>
			<dl>
				<dt data-id="${productsArr[0].goodsId}">
					<a href="cart-item.html?goodsId=${productsArr[0].goodsId}&brandId=${productsArr[0].brandId}">
						<img src="${productsArr[0].goodsImgUrl}" alt="">
					</a>
				</dt>
				<dd>${productsArr[0].goodsMsg}</dd>
				<dd>${productsArr[0].goodsName}</dd>
				<dd>¥${productsArr[0].minPrice} <span class="zan">&#xe6c8;</span></dd>
			</dl>
			<dl>
				<dt data-id="${productsArr[0].goodsId}">
					<a href="cart-item.html?goodsId=${productsArr[0].goodsId}&brandId=${productsArr[0].brandId}">
						<img src="${productsArr[0].goodsImgUrl}" alt="">
					</a>
				</dt>
				<dd>${productsArr[0].goodsMsg}</dd>
				<dd>${productsArr[0].goodsName}</dd>
				<dd>¥${productsArr[0].minPrice} <span class="zan">&#xe6c8;</span></dd>
			</dl>
		`
	}
	$('.products')[0].innerHTML = html
	
	
	//跳转商品详情页
	let oProducts = $('.products dl dt')
	console.log(oProducts)
	for(let i=0;i<oProducts.length;i++){
		oProducts[i].onclick=function(){
			console.log(this.getAttribute('data-id'))
			localStorage.setItem('goodsId',this.getAttribute('data-id'))
			location.href='cart-item.html'
		}
	}
	
	
	let zan=document.querySelectorAll('.zan')
	for(let i=0;i<zan.length;i++){
		let count=1;
		zan[i].onclick=function(){
			count++;
			if(count%2==0){
				zan[i].innerHTML='&#xe85d;';
				zan[i].style.color='red';
				
			}else{
				zan[i].innerHTML='&#xe6c8;';
				zan[i].style.color='black';
			}
			
		}
		
	}
})


